<template>
  <base-breadcrumb>
    <a-card>
      <title-name title="商务工作总计划"></title-name>
      <searchData
              :search-data="searchArr"
              @search="search"
              v-if="pageType==='view'"
      />
      <div class="mb12" v-if="!isAudit&&!isConsultation">
        <a-form>
          <a-row>
            <a-col :span="6">
              <a-form-item label="中标时间" style="margin-bottom: 0;display: flex">
                <a-date-picker
                        v-model:value="formObj.winningTimeStr"
                        type="date"
                        placeholder="请选择中标时间"
                        style="width: 100%"
                        format="YYYY-MM-DD"
                        value-format="YYYY-MM-DD"
                        :disabled="pageType==='view'"
                />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="竣工时间"  style="margin-bottom: 0;display: flex">
                <a-date-picker
                        v-model:value="formObj.completeDateStr"
                        type="date"
                        placeholder="请选择竣工时间"
                        style="width: 100%"
                        format="YYYY-MM-DD"
                        value-format="YYYY-MM-DD"
                        :disabled="pageType==='view'"
                />
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-button type="primary"
                        :disabled="pageType==='view'"
                        @click="updateDeatilsByProjetId" style="margin-left: 10px;margin-top: 3px">保存时间</a-button>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <!-- 作为审批详情和调整的的时候展示 -->
      <div v-if='pageType==="change" || showAdjustDiv' style='margin-bottom: 15px'>
        <title-name title="商务工作总计划调整"></title-name>
        <a-form>
          <a-row>
            <a-col :span="6">
              <a-form-item label="调整内容"  style="margin-bottom: 0;display: flex">
                <BaseTextarea :disabled='pageType !=="change" &&showAdjustDiv' :maxLength=500   placeholder="请输入调整内容" v-model="formObj.adjustContent"></BaseTextarea>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="调整原因" style="margin-bottom: 0;display: flex">
               <!-- 作为审批详情的时候不可编辑 -->
                <BaseTextarea
                  :maxLength=500 :disabled='pageType !=="change" &&showAdjustDiv'  placeholder="请输入调整原因" v-model="formObj.adjustReason"></BaseTextarea>
              </a-form-item>
            </a-col>
            <a-col :span="6">
              <a-form-item label="附件"  style="margin-bottom: 0;display: flex">
                <UploadList
                  v-if='pageType ==="change"'
                  :businessCode="'BM31'" :uploadArrys.sync="formObj.adjustFiles"  multiple></UploadList>
                <file-link v-else :file-list="formObj.adjustFiles"></file-link>
              </a-form-item>
            </a-col>
          </a-row>
        </a-form>
      </div>

      <div class="mb12">
        <a-button type="primary" @click="openAll">展开全部</a-button>
        <a-button type="primary" class="ml12" @click="expandedRowKeys = []">收起全部</a-button>
        <a-button type="primary"
                  @click="exportExcel"
                  :loading="exportLoading"
                  class="ml12" v-if="pageType==='view'">导出Excel</a-button>
      </div>
      <div class="mb12">
        <a-alert class="mb12" style="margin-top:3px" type="info" show-icon  v-if="pageType==='view'">
          <template slot="message">
            项目：<span style="color: #0E7ED0;">{{ form.projectName }}</span>
            节点共<span style="color: #0E7ED0;">{{ form.nodeNum || 0 }}</span>项
            周期天数<span style="color: #0E7ED0;">{{ form.cycleDaysNum || 0 }}</span>天
            周期间隔<span style="color: #0E7ED0;">{{ form.cycleInterval }}</span>
          </template>
        </a-alert>
      </div>
      <a-table
              row-key="id"
              :columns="columns"
              :data-source="dataSource"
              :expanded-row-keys.sync="expandedRowKeys"
              :expandIconColumnIndex="1"
              @expandedRowsChange="expandedRowsChange"
              bordered
              :pagination="false"
              :loading="pageLoading"
      >
        <template slot="index" slot-scope="text, record, index">
          <span>{{ record.index }}</span>
        </template>
        <template slot="statusName" slot-scope="text">
          <span :class="setColor(text)">{{ text }}</span>
        </template>
        <div slot="workName" slot-scope="text,record, index" class="requiredFormItem">
          <a-input v-if="record.showInput&&pageType!=='view'" placeholder="请输入" v-model="record.workName" @change="handleInputChange($event, record)"></a-input>
          <span v-else>{{ text }}</span>
        </div>
        <template slot="startData" slot-scope="text, record, index">
          <a-date-picker format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                         v-model="record.planStartDate"
                         :disabledDate="(current)=>{
                           return disabledStartDate(current, record)
                         }"
                         @change="handleDateChange($event, record)"
                         style="width: 120px" class="requiredFormItem" v-if="record.showTime&&pageType!=='view'" />
          <span v-else>{{ text }}</span>
        </template>
        <template slot="endDate" slot-scope="text, record, index">
          <a-date-picker  format="YYYY-MM-DD" value-format="YYYY-MM-DD"
                          v-model="record.planEndDate"
                          :disabledDate="(current)=>{
                           return disabledEndtDate(current, record)
                         }"
                          @change="handleDateChange($event, record)"
                          style="width: 120px" class="requiredFormItem" v-if="(record.showEndTime || record.showTime)&&pageType!=='view'" />
          <span v-else>{{text}}</span>
        </template>
        <template slot="action" slot-scope="text,record,index">
          <a v-if="record.showAddBtn" @click="addTask(record)">增加子任务</a>
          <!--  总包其中结算手动新增的可以删（关键用户提的，他们有时候手误）  -->
          <a v-else-if="record.showDelBtn&&(record.sortNum !==1 || (record.parentIdTypeCode==='2212' && record.isAdd) )" style="color: #D9001B" @click="delRow(record)">删除</a>
        </template>
      </a-table>
    </a-card>
    <div class="pub-header-btn page-btn-right-top"  v-if="!isAudit&&!isConsultation">
      <a-button
              :loading="loading"
              type="primary"
              @click="save"
              v-if="pageType!=='view'"
      > 保存草稿 </a-button>
      <a-button
              :loading="loading"
              type="primary"
              @click="submit"
              v-if="pageType!=='view'"
      > 提交 </a-button>
      <a-button
              @click="$close"
      > 关闭 </a-button>
    </div>
    <selectApprover
            :business-id="businessId"
            :process-config="setProcessConfig"
    />
  </base-breadcrumb>
</template>

<script>
  import {masterWorkPlanDetailByPage, masterWorkPlanSaveOrSubmit, masterWorkPlanDetailCount, masterWorkPlanExportExcel, updateDeatilsByProjetId} from "@/api/businessAffairs/workPlan"
  import moment from 'moment'
  import deepClone from 'lodash.clonedeep'
  import UploadList from '@/components/UploadList'
  const columns = [
    {
      title: '编号',
      dataIndex: 'index',
      width: '80px',
      scopedSlots: { customRender: 'index' }
    },
    {
      title: '工作名称',
      dataIndex: 'workName',
      scopedSlots: { customRender: 'workName' }
    },
    {
      title: '计划开始时间',
      dataIndex: 'planStartDate',
      width: '140px',
      scopedSlots: { customRender: 'startData' }
    },
    {
      title: '计划完成时间',
      dataIndex: 'planEndDate',
      width: '140px',
      scopedSlots: { customRender: 'endDate' }
    },
    {
      title: '周期',
      dataIndex: 'cycleDays',
    },
    {
      title: '操作',
      width: '120px',
      scopedSlots: { customRender: 'action' }
    },
  ];
  const status = [
    { label: '未提交', value: '未提交' },
    { label: '按期完成', value: '按期完成' },
    { label: '逾期完成', value: '逾期完成' },
    { label: '逾期未完成', value: '逾期未完成' },
    { label: '完成审批中', value: '完成审批中' },
    { label: '完成审批不通过', value: '完成审批不通过' }
  ]
  export default {
    name: 'b'+ Date.now(),
    components: { UploadList },
    data() {
      return {
        businessId: '',
        processConfig: 4,
        setProcessConfig: null,
        form: {},
        exportLoading: false,
        pageLoading: false,
        pageType: 'Add',
        loading: false,
        dataSource: [],
        columns: {},
        expandedRowKeys: [],
        searchArr: [
          {
            name: '工作名称',
            value: 'workName',
            type: 'input'
          },
          {
            name: '计划开始时间',
            value: 'planStartDate',
            type: 'dateRange'
          },
          {
            name: '计划完成时间',
            value: 'planEndDate',
            type: 'dateRange'
          },
          {
            name: '实际完成时间',
            value: 'compleDate',
            type: 'dateRange'
          },
          {
            name: '状态',
            value: 'statusName',
            type: 'select',
            data: status
          }
        ],
        queryParams: {},
        isHistory: 0,
        formObj:{
          winningTimeStr: '',
          completeDateStr: '',
          projectId: '',
          adjustReason: '',
          adjustContent: '',
          adjustFiles: [],

        },
        showAdjustDiv: false,
        isClick:false
      };
    },
    props: {
      // 是否作为审批详情
      isAudit: {
        type: Boolean,
        default: false
      },
      // 是否作为意见征询
      isConsultation: {
        type: Boolean,
        default: false
      },
    },
    async created() {
      this.columns = deepClone(columns)
      let query = this.$route.query
      this.pageType = query.pageType
      this.isHistory = query.isHistory ? 1 : 0
      if(query.businessId) {
        this.pageType = 'view'
      }
      // if(this.pageType === 'view'&&!this.isHistory) {
      if(this.pageType === 'view') {
        this.columns.splice(-1, 1)
        let arr = [
          {
            title: '实际完成时间',
            dataIndex: 'compleDate',
          },
          {
            title: '状态',
            dataIndex: 'statusName',
            scopedSlots: { customRender: 'statusName' }
          },
        ]
        this.columns = [...this.columns, ...arr]
        this.masterWorkPlanDetailCount()
      } else if(this.pageType === 'view'&&this.isHistory==1) {
        this.masterWorkPlanDetailCount()
        //查看历史
        this.columns.splice(-1, 1)
      }
      if(this.pageType === 'change'){
        //调整的时候为了显示新增加的3个字段页调一下接口
        this.masterWorkPlanDetailCount()
      }
      this.formObj.winningTimeStr = this.$route.query.winningTime
      this.formObj.completeDateStr = this.$route.query.completedDate
      if( this.formObj.winningTimeStr && this.formObj.completeDateStr) {
        this.isClick = true
      }
      // 查看历史版本
      if(query.isHistory==1) {
        // this.searchArr =  this.searchArr.slice(0, 3)
      }
      this.masterWorkPlanDetailByPage()
      this.processConfig = await this.$getConfigFn('comm_master_work_plan')
    },

    methods: {
      updateDeatilsByProjetId() {
        /*start 20240125(hezhen)*/
       /* 校验总包结算定案“计划开始时间不能大于计划完成时间”*/
        if(this.dataSource && this.dataSource.length >0 && this.formObj.completeDateStr){
          const target = this.dataSource.filter((item) =>item.typeCode==='2218')
          let planStartDate = moment(this.formObj.completeDateStr).add(1, 'days')
          if(target){
            if(moment(target[0].planEndDate).isSameOrBefore(planStartDate)){
              this.$message.error('总包结算定案“计划开始时间不能大于计划完成时间”')
              return
            }
          }
        }
        /*end*/
        this.formObj.projectId = this.$route.query.projectId
        this.pageLoading = true
        updateDeatilsByProjetId(this.formObj).then(() => {
          this.pageLoading = false
          this.isClick = true
          this.masterWorkPlanDetailByPage()
        }).catch(()=>{
          this.pageLoading = false
        })
      },
      setColor(name) {
        switch (name) {
          case '按期完成':
            return 'c-95F204';
          case '逾期完成':
            return 'c-D9001B';
          case '逾期未完成':
            return 'c-EC808D';
          default:
            return  ''
        }
      },
      exportExcel() {
        let data = {
          masterPlanId: this.$route.query.id,
          isHistory: this.isHistory,
          ...this.queryParams
        }
        this.exportLoading = true
        masterWorkPlanExportExcel(data).then(res=>{
            this.handleDownload(res)
        })
      },
      /**
       * @description: 下载
       * @return {void}
       */
      handleDownload(res) {
        const blob = new Blob([res.data])
        const filename = decodeURIComponent(res.headers['content-disposition'].split('filename=')[1])
        const downloadElement = document.createElement('a')
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        downloadElement.href = href
        downloadElement.download = filename// 获取文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() //点击下载
        document.body.removeChild(downloadElement) //下载完成移除元素
        window.URL.revokeObjectURL(href) //释放blob对象
        this.exportLoading = false
      },
      masterWorkPlanDetailCount() {
        let data = {
          id: this.$route.query.id,
          isHistory: this.isHistory
        }
        masterWorkPlanDetailCount(data).then(res=>{
          this.form = res.data;
          if(res.data){
            this.formObj.adjustReason  = this.form.adjustReason
            this.formObj.adjustContent = this.form.adjustContent
            this.formObj.adjustFiles = this.form.adjustFileInfoList || []
            this.showAdjustDiv = this.form.adjustReason || this.form.adjustContent
          }
        })
      },
      // 校验必填 丙方arr
      checkDate() {
        let arr = JSON.parse(JSON.stringify( this.dataSource))
        let flag = true
        arr.forEach(item=>{
          if(item.showTime||item.showEndTime) {
            if(!item.planStartDate || !item.planEndDate) {
              flag = false
            }
          }
          if(item.children) {
            item.children.forEach(el=>{
              if(item.typeCode !='2214') {
                if(!el.planStartDate || !el.planEndDate || !el.workName) {
                  flag = false
                }
              }
              if(el.isAdd) {
                delete el.id
              }
            })
          }
        })
        if(!flag) {
          this.$message.warning('请填写完所有必填项信息')
          return false
        }
        return arr
      },
      save() {
        if(!this.formObj.winningTimeStr) {
          this.$message.warning('请设置中标时间')
          return
        }
        if(!this.formObj.completeDateStr) {
          this.$message.warning('请设置竣工时间')
          return
        }
        if(!this.isClick) {
          this.$message.warning('请点击设置时间')
          return
        }
        let arr = this.checkDate()
        if(!arr) return
        let data = {
          id: this.$route.query.id,
          auditStatus: 'DRAFT',
          detailsVOList: arr
        }
        data.creatorName = this.$userInfo().name
        this.appendAdjustField(data)
        this.loading = true
        masterWorkPlanSaveOrSubmit(data).then(res=>{
          this.loading = false
          if(res.code === 200) {
            this.$message.success("保存草稿成功")
            this.$router.replace('/businessAffairs/workPlan/workMasterPlan')
          } else {
            this.$message.error("保存草稿失败")
          }
        }).catch(()=>{
          this.loading = false
        })
      },
      submit() {
        if(!this.formObj.winningTimeStr) {
          this.$message.warning('请设置中标时间')
          return
        }
        if(!this.formObj.completeDateStr) {
          this.$message.warning('请设置竣工时间')
          return
        }
        if(!this.isClick) {
          this.$message.warning('请点击设置时间')
          return
        }
        let arr = this.checkDate()
        if(!arr) return

        let data = {
          id: this.$route.query.id,
          auditStatus: 'SUBMITTED',
          detailsVOList: arr
        }
        if(!this.appendAdjustField(data,true)){
          return
        }

        this.submitApprovalConfirm( this.processConfig, (flag) => {
          if (!flag) {
            this.loading = false
            return
          }
          data.creatorName = this.$userInfo().name
          this.loading = true
          masterWorkPlanSaveOrSubmit(data).then(res=>{
            this.loading = false
            if(res.code === 200) {
              this.$message.success("提交成功")
              this.businessId = this.$route.query.id;
              this.setProcessConfig = this.processConfig;
              // this.$router.replace('/businessAffairs/workPlan/workMasterPlan')
            } else {
              this.$message.error("提交失败")
            }
          }).catch(()=>{
            this.loading = false
          })
        })

      },
      appendAdjustField(data,showError = false) { //调整界面加了3个字段且是2个必填
        if(this.pageType !=='change'){
          return true
        }
        if( !this.formObj.adjustContent && showError){
          this.$message.warning('请填写调整内容')
          return false
        }
        if( !this.formObj.adjustReason && showError){
          this.$message.warning('请填写调整原因')
          return false
        }


        if(data && this.pageType==='change'){
          data.adjustReason = this.formObj.adjustReason
          data.adjustContent = this.formObj.adjustContent
          data.adjustFiles = this.formObj.adjustFiles
        }
        return true
      },
      masterWorkPlanDetailByPage() {
        let data = {
          masterPlanId: this.$route.query.id,
          isHistory: this.isHistory,
          ...this.queryParams
        }
        this.pageLoading = true
        masterWorkPlanDetailByPage(data).then(res=>{
          let index = 0
          res.data.forEach(item=>{
             ++index
            item.index = index
            if(item.children.length == 0) {
              item.children = null
            } else {
              item.children.forEach(el=>{
                el.children = null
              })
            }
            /*start-20240125（hezhen）*/
            if(item.typeCode === '2218') {
              //“总包结算定案”计划完成时间可自定义
              item.showEndTime = true
            }
            /*end*/
            if(item.typeCode === '2206' || item.typeCode === '2207') {
              item.showTime = true
            }
             else if(item.typeCode === '2208' || item.typeCode === '2209'
              || item.typeCode === '2212' || item.typeCode === '2213') {
              //总包施工图预算也要添加子节点,不需要特别处理
              /*if(item.typeCode === '2208'&& this.pageType === 'change') {
                item.showAddBtn = false
              } else {
                item.showAddBtn = true
              }*/
              item.showAddBtn = true

              if(item.children&&item.children.length) {
                item.children.forEach((el, index)=>{
                    item.sortNum = index + 1
                  if(this.pageType === 'change') {
                    //总包施工图预算也要添加子节点,不需要特别处理
                    /*if (item.typeCode === '2208') {
                      el.showTime = false
                      el.showInput = false
                      el.showDelBtn = false
                    } else {
                      if(moment(el.planStartDate).isSameOrBefore(moment(), 'days')) {
                        el.showTime = false
                        el.showInput = false
                        el.showDelBtn = false
                      } else {
                        el.showTime = true
                        el.showInput = true
                        el.showDelBtn = false
                      }
                    }*/
                    if(moment(el.planStartDate).isSameOrBefore(moment(), 'days')) {
                      el.showTime = false
                      el.showInput = false
                      el.showDelBtn = false
                    } else {
                      el.showTime = true
                      el.showInput = true
                      el.showDelBtn = false
                    }
                  } else {
                    el.showTime = true
                    el.showInput = true
                    el.showDelBtn = true
                  }

                })
              }

            }

            if(item.children&&item.children.length) {
              item.children.forEach(el=>{
                ++index
                el.index = index
              })
            }
          })
          this.dataSource = res.data
          this.expandedRowKeys = []
          this.dataSource.forEach((item)=>{
            this.expandedRowKeys.push(item.id)
            if(item.typeCode === '2208' || item.typeCode === '2209'
              //|| item.typeCode === '2212' //总包期中结算不再自动生成一条（即非必填）
              || item.typeCode === '2213'){
              // 默认生成一条
              if((!item.children || item.children.length === 0)&&this.pageType === 'edit') {
                this.addTask(item, true)
              }
            }
          })
          const obj2213 = this.dataSource.find(item => item.typeCode === '2213')
          const obj2214 = this.dataSource.find(item => item.typeCode === '2214')
          const arr = []
          obj2213.children.forEach(item=>{
            let o =  obj2214.children.find(el => el.associationCode === item.associationCode)
            if(!o) {
              // console.log(item, '222222')
              const obj2 = {
                sortNum: 1,
                associationCode: 0,
                id: el.typeCode + new Date().getTime(),
                isAdd:  true,
                parentId: obj2214.id,
                parentIdTypeCode: el.typeCode,
                workName: item.workName + '分供实际效益分析', //分供实际效益分析
                planStartDate: "",
                planEndDate: '',
                cycleDays: ''
              }
              arr.push(obj2)
            } else {
              arr.push(o)
            }

          })
          obj2214.children = arr
          // 重新排序 防止对应不上
          obj2213.children.forEach((item, index)=>{
            item.sortNum = index + 1
            item.associationCode =  index + 1
          })
          obj2214.children.forEach((item, index)=>{
            item.sortNum = index + 1
            item.associationCode =  index + 1
          })
          this.pageLoading = false
          /*start 将项目效益审计资料上报2220 《=》成本总结与还原2219 调换位置*/
          this.dataSource.sort((a,b)=>{
            if(a.typeCode==='2220' && b.typeCode === '2219'){
               return  -1
            }else{
               return  +a.typeCode - b.typeCode
            }
          })
          /*end*/

          this.$forceUpdate()
        }).catch(()=>{
          this.pageLoading = false
        })
      },
      search(val) {
        this.queryParams = val
        if(this.queryParams.planStartDate && this.queryParams.planStartDate.length) {
          this.queryParams.planStartDateBegin = moment(this.queryParams.planStartDate[0]).format("YYYY-MM-DD")
          this.queryParams.planStartDateEnd = moment(this.queryParams.planStartDate[1]).format("YYYY-MM-DD")
          delete  this.queryParams.planStartDate
        }
        if(this.queryParams.planEndDate && this.queryParams.planEndDate.length) {
          this.queryParams.planEndDateBegin = moment(this.queryParams.planEndDate[0]).format("YYYY-MM-DD")
          this.queryParams.planEndDateEnd = moment(this.queryParams.planEndDate[1]).format("YYYY-MM-DD")
          delete  this.queryParams.planEndDate
        }
        if(this.queryParams.compleDate && this.queryParams.compleDate.length) {
          this.queryParams.compleDateBegin = moment(this.queryParams.compleDate[0]).format("YYYY-MM-DD")
          this.queryParams.compleDateEnd = moment(this.queryParams.compleDate[1]).format("YYYY-MM-DD")
          delete  this.queryParams.compleDate
        }
        this.masterWorkPlanDetailByPage()
      },
      addTask(row, isInit=false) {
        row.children =  row.children || []
        const index = row.children.length
        const obj = {
          sortNum: index+1,
          id: row.typeCode + new Date().getTime(),
          associationCode: row.children.length + 1,
          isAdd:  true,
          parentId: row.id,
          parentIdTypeCode: row.typeCode,
          workName: '',
          planStartDate: "",
          planEndDate: '',
          cycleDays: '',
          showTime: true,
          showInput: true,
          showDelBtn: true
        }
        row.children.push(obj)
        if(!isInit) {
          if(!this.expandedRowKeys.includes(row.id)) {
            this.expandedRowKeys.push(row.id)
          }
        }

        if(row.typeCode === '2213') {
          // 这里找到 分包分供实际效益分析节点
         const el = this.dataSource.find(item=>item.typeCode === '2214')
         if(!isInit) {
           if(!this.expandedRowKeys.includes(el.id)) {
             this.expandedRowKeys.push(el.id)
           }
         }
          el.children = el.children || []
          const obj2 = {
            sortNum: index+1,
            associationCode: el.children.length + 1,
            id: el.typeCode + new Date().getTime(),
            isAdd:  true,
            parentId: el.id,
            parentIdTypeCode: el.typeCode,
            workName: '', //分供实际效益分析
            planStartDate: "",
            planEndDate: '',
            cycleDays: ''
          }
          el.children.push(obj2)
        }
        this.$forceUpdate()
      },
      handleInputChange(val, row) {
        if(row.parentIdTypeCode === '2213') {
          // 这里找到 分包分供实际效益分析节点
          const el = this.dataSource.find(item => item.typeCode === '2214')
         const obj = el.children.find(item=> item.associationCode === row.associationCode)
          obj.workName = row.workName+'分供实际效益分析'
          this.$forceUpdate()
        }
      },
      delRow(row) {
       const currentRow = this.dataSource.find(item => item.typeCode === row.parentIdTypeCode)
        if(row.parentIdTypeCode === '2213') {
          // 这里找到 分包分供实际效益分析节点
          const el = this.dataSource.find(item => item.typeCode === '2214')
          el.children.splice(row.sortNum-1, 1)
          el.children.forEach((item, index)=>{
            item.sortNum = index + 1
            item.associationCode = index+1
          })
        }
        currentRow.children.splice(row.sortNum-1, 1)
        currentRow.children.forEach((item, index)=>{
          item.sortNum = index + 1
          item.associationCode = index+1
        })

        this.$forceUpdate()
      },
      // 日期改变的时候需要计算周期
      handleDateChange(val,row) {
        if(row.planEndDate&&row.planStartDate) {
          row.cycleDays = this.getDiffDay(row.planStartDate, row.planEndDate) + 1
        }
        this.setParentDate(row)

        // if(row.parentIdTypeCode === '2213') {
        //   // 这里找到 分包分供实际效益分析节点
        //   const el = this.dataSource.find(item => item.typeCode === '2214')
        //   if(row.planStartDate) {
        //     el.children[row.sortNum - 1].planStartDate = moment(row.planStartDate ).add(1,'days').format('YYYY-MM-DD')
        //   }
        //  if(row.planEndDate) {
        //    el.children[row.sortNum - 1].planEndDate = moment(row.planEndDate).add(7,'days').format('YYYY-MM-DD')
        //  }
        //   if( el.children[row.sortNum - 1].planEndDate && el.children[row.sortNum - 1].planStartDate) {
        //     el.children[row.sortNum - 1].cycleDays = this.getDiffDay( el.children[row.sortNum - 1].planStartDate, el.children[row.sortNum - 1].planEndDate) + 1
        //   }
        //   this.setParentDate(el.children[0])
        // }
      },
      // 设置父级时间
      setParentDate(row) {
        // 计算最小计划开始时间值
        if(row.parentIdTypeCode) {
          const parentNode = this.dataSource.find(item=>item.typeCode === row.parentIdTypeCode)
          // 收集开始时间和 结束时间
          const startDateArrs = [], endDateArrs = []
          parentNode.children.forEach(item=>{
            if(item.planStartDate) {
              startDateArrs.push(new Date(item.planStartDate).getTime())
            }
            if(item.planEndDate) {
              endDateArrs.push(new Date(item.planEndDate).getTime())
            }
          })
          if(startDateArrs.length) {
            parentNode.planStartDate = moment(Math.min(...startDateArrs)).format('YYYY-MM-DD')
          }
          if(endDateArrs.length) {
            parentNode.planEndDate = moment(Math.max(...endDateArrs)).format('YYYY-MM-DD')
          }

          if(parentNode.planStartDate &&  parentNode.planEndDate) {
            parentNode.cycleDays = this.getDiffDay(parentNode.planStartDate,  parentNode.planEndDate) + 1
          }

        }
      },
      // 展开全部
      openAll() {
        this.expandedRowKeys = []
        this.dataSource.forEach(item=>{
          this.expandedRowKeys.push(item.id)
        })
      },
      // 点击+号
      expandedRowsChange(expandedRowKeys) {
        this.expandedRowKeys = expandedRowKeys
      },
      // 获取时间周期
      getDiffDay(date_1, date_2){
        let totalDays, diffDate
        let myDate_1 = Date.parse(date_1)
        let myDate_2 = Date.parse(date_2)
        diffDate = Math.abs(myDate_1 - myDate_2)
        totalDays = Math.floor(diffDate / (1000 * 3600 * 24))
        return totalDays
      },
      disabledStartDate(current, record) {
        if(record.planEndDate) {
          return current && current > moment(record.planEndDate).subtract(1,'days').endOf('day')
        }
        return false
      },
      disabledEndtDate(current, record) {
        if(record.planStartDate) {
          return current && current < moment(record.planStartDate).subtract(1,'days').endOf('day')
        }
        return false
      }
    }
  };
</script>

<style scoped lang="less">
 ::v-deep .ant-table-row-expand-icon {
    display: inline-block;
  }
 ::v-deep .requiredFormItem {
   display: inline-block;
   width: 80%;
 }
 .c-95F204 {
   color: #95F204;
 }
 .c-EC808D {
   color: #EC808D;
 }
 .c-D9001B {
   color: #D9001B;
 }
</style>